/*
 * input.h
 *
 * Created: 6/17/2013 11:06:49 PM
 *  Author: Tim
 */ 


#ifndef INPUT_H_
#define INPUT_H_

#include <avr/io.h> 
#include <stdbool.h>

#include "../packets/status.h"
#include "../board/board.h"
#include "../features/stateMachine.h"
#include "../packets/structs/msgHeaderDefs.h"
#include "../packets/handlers/genPacketHandler.h"
#include "../packets//handlers/adcPacketHandler.h"
#include "../packets//handlers/dacPacketHandler.h"
#include "../packets//handlers/dioPacketHandler.h"
#include "../packets/handlers/encPacketHandler.h"
#include "../packets/handlers/tmrPacketHandler.h"
#include "../packets/handlers/pwmPacketHandler.h"
#include "../packets/handlers/superPacketHandler.h"

static inline uint8_t globalMsgHandler(uint8_t *packet)
{
	switch (packet[1])
	{
		//Initializations
		case (adcInit_mh):
			return adcInitHandler((uint8_t *)packet);
		break;
		case (dacEnable_mh):
			return dacEnableHandler((uint8_t *)packet);
		break;
		case (digitalInEnable_mh):
		asm("nop");
			return digitalInEnableHandler((uint8_t *)packet);
		break;
		case (digitalOutEnable_mh):
		asm("nop");
			return digitalOutEnableHandler((uint8_t *)packet);
		break;	
		case (encInit_mh):
			return encInitHandler((uint8_t *)packet);
		break;
		case (tmrSetFreq_mh):
			return tmrSetFreq((uint8_t *)packet);
		break;
		case (startProgram_mh):
			startProgram();
			//this is a hack
			sendGenAck(startProgram_mh,1);
			return 1;
		break;
		case (servoEnable_mh):
			return servoEnableHandler((uint8_t *)packet);
		break;
		case (motorEnable_mh):
			return motorEnableHandler((uint8_t *)packet);
		break;
		
		//run time messages
		case (stopProgram_mh):
			stopProgram();
			//this is a hack
			sendGenAck(stopProgram_mh,1);
			return 1;
		break;
		case (resetDaq_mh):
			resetDaq();
			sendGenAck(resetDaq_mh,1);
		return(1);
		
		case (outputSuperPacket_mh):
			asm("nop");
			return outputSuperPacketHandler((uint8_t *)packet);
		break;
		case (actuatorSuperPacket_mh):
			asm("nop");
			return actuatorSuperPacketHandler((uint8_t *)packet);
		break;
		
	}
}

#endif /* INPUT_H_ */